
/**
/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes') 
  , announcement = require('./routes/announcement') // Announcement
  , message = require('./routes/message') // Message
  , user = require('./routes/user') // users object
  , settings = require('./routes/settings') // users object
  , login = require('./routes/login') // login object
  , quicknav = require('./routes/quicknav') // quick navigation object
  , online = require('./routes/online') // online panel object
  , comment = require('./routes/comment')  // comment panel object
  , ws = require('./routes/workspace') // workspace object
  , form = require('./routes/form') // form object
  , tables = require('./routes/tables') // user forms object
  , formView = require('./routes/formview') // user forms object
  , wfView = require('./routes/workflowview') // user/admin workflow view
  , reports = require('./routes/reports') // reports onject
  , request = require('./routes/loadrequest') // request object
  , requestview = require('./routes/requestview') // request view object
  , wf = require('./routes/workflow')
  , forms = require('./routes/formsXML')
  , orgChart = require('./routes/orgchart')
  , loadWfElem = require('./routes/aaron/loadWfElem')
  , loadActionStatus = require('./routes/aaron/loadActionStatus')
  , loadActionButton = require('./routes/aaron/loadActionButton')
  , loadUsersForDepartment = require('./routes/aaron/loadUsersForDepartment')
  , requestJSON = require('./routes/requestJSON') // requests JSON
  , formJSON = require('./routes/formJSON') // forms JSON
  , userJSON = require('./routes/userJSON') // users JSON
  , user_registration = require('./routes/user_registration') // users JSON
  , orgChart = require('./routes/orgchart')
  , loadWfElem = require('./routes/aaron/loadWfElem')
  , loadActionStatus = require('./routes/aaron/loadActionStatus')
  , loadActionButton = require('./routes/aaron/loadActionButton')
  , loadUsersForDepartment = require('./routes/aaron/loadUsersForDepartment')
  , orgChartViews = require('./routes/orgChartView')
  , discussions = require('./routes/discussions')
  , http = require('http') 
  , path = require('path');

var app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});
// Added Page
app.get('/message', message.msg);


app.get('/', routes.index); // load home page
app.get('/users', user.list); // load users
app.get('/forms/:ID', forms.load); // load users
app.get('/settings', settings.load); // load users
app.get('/workspace', ws.load); // load workspace
app.post('/workspace', ws.save); // save workspace
app.get('/form/:ID/:requestID', form.load); // load request
app.post('/form/:ID/:requestID', form.save); // save request
app.get('/loadrecord/:tblname/:id', request.load); // load request details
app.get('/tables',tables.load ); //load available forms
app.get('/reports',reports.load ); // load available reports
app.get('/recordview/:id/:tblname/:formName',requestview.load); // load request view
app.get('/login', login.load);  // load login page
app.get('/quicknav',quicknav.load); // load quick navigation panel
app.get('/online',online.load) // load online users panel
app.get('/comment/:tableID/:requestID/:comment',comment.load) // load request comments
app.get('/formview',formView.load); //load workflow action button
app.get('/workflowview',wfView.load); //load workflow action button
app.get('/requestJSON/:tblname/:id',requestJSON.load); //initialize get method request object
app.get('/formJSON/:id',formJSON.load); //initialize get method form object
app.get('/userJSON/:id',userJSON.load); //initialize get method form object
app.post('/user_registration', user_registration.save); // register user

// Announcement and Add Comment

app.get('/announcement', announcement.getAnnouncement);
//app.get('/announcement/:action', announcement.getCommenttoDB);
app.post('/announcement/:value/:postType/:date/:companyID', announcement.save); // save comment to db.
app.post('/announcement/:announcement_id/:action', announcement.destroy); // delete post to db.



/*****Aaron****/
app.get('/workflow/:wfID/:formID', wf.load); //load the workflow
app.get('/loadWfElem/:id/:selected',loadWfElem.load); //for changing the processor type
app.get('/loadActionStatus',loadActionStatus.load); //for action status
app.get('/loadActionButton/:formID',loadActionButton.load); //for action button
app.get('/orgChart', orgChart.load); //load the orgchart
app.get('/orgchartview', orgChartViews.loadList); //load the orgchart list
app.get('/orgChart/:id', orgChartViews.loadObjects); //load the orgchart list
app.get('/warningOrgchartActivate',orgChart.getCountOrgchart)
app.get('/loadUsersForDepartment/', loadUsersForDepartment.load); //load users for orgchart
app.post('/saveOrgchart/:nodes/:lines/:title/:desc/:status', orgChart.save); //save orgchart
app.post('/saveWorkflow/:nodes/:lines/:form_id/:workFlowTitle/:workFlowDesc/:delegateRequest', wf.save); //save workflow
app.post('/updateOrgchartStatus',orgChart.updateStatus)

/*****Discussions****/
app.post('/discussions/post', discussions.newPost);
app.post('/discussions/comment', discussions.comment);

app.get('/discussions/postsWithComments', discussions.postsWithComments);
app.get('/discussions/post/:postId', discussions.getPost);
app.get('/discussions/post/:postId/comments', discussions.postComments);
app.get('/comment/:commentId', discussions.getComment);

app.post('/discussions/updatepost', discussions.updatePost);

app.get('/discussions/delete/:postId', discussions.deletePost);
app.get('/discussions/deletecomment/:commentId', discussions.deleteComment);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});
